﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Webadmin_Modules_About_ListEdit : bzAdminUCBase
{
    public string _Act = "";
    public string _ID = "";
    public DataTable _dt = new DataTable();
    private bzDomain bz = new bzDomain();
    public DataRow dr = null;
    override protected void loadAction()
    {
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        _ID = Request.QueryString["ID"] == null ? "-1" : Request.QueryString["ID"];
        _dt = bz.getRecord(_ID, "-1");
        if (_dt.Rows.Count > 0)
        {
            dr = _dt.Rows[0];
        }
        if (!IsPostBack)
        {
            switch (_Act)
            {
                case "Edit": this.loadEdit(); break;
                case "Add": this.resetData(); break;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator, bzSiteOption.Note.About, "About");
    }
   // TextBox txtTitleEN = new TextBox();
   // TextBox txtContentEN = new TextBox();
    private void loadEdit()
    {
        this.Navigator = this.AdminLang["MenuHostting"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuHosttinglist"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["Edit"].ToString();
        this.btnUpdate.Text = this.AdminLang["Edit"].ToString();
        _dt = bz.getRecord(_ID);
        DataRow dr = _dt.Rows[0];

        this.txtTitleVN.Text = dr["TitleVN"].ToString();
       // this.txtTitleEN.Text = dr["TitleEN"].ToString();
        this.txtContentVN.Text = Server.HtmlDecode(dr["ContentVN"].ToString());
       // this.txtContentEN.Text = Server.HtmlDecode(dr["ContentEN"].ToString());
        //this.lblLink.Text = dr["Upload"].ToString();

        this.rdForward_1.Enabled = false;
        this.rdForward_0.Checked = true;
        this.rdEnabled_1.Checked = Convert.ToInt16(dr["Enabled"]) <= 0 ? false : true;
        this.rdEnabled_0.Checked = !this.rdEnabled_1.Checked;
    }
    private void resetData()
    {
        this.Navigator = this.AdminLang["MenuHostting"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuHosttinglist"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["AddNew"].ToString();
        this.txtTitleVN.Text = "";
       // this.txtTitleEN.Text = "";

        this.txtContentVN.Text = "";
      //  this.txtContentEN.Text = "";

        this.rdForward_0.Checked = false;
        this.rdForward_1.Checked = !this.rdForward_0.Checked;
        this.btnUpdate.Text = this.AdminLang["AddNew"].ToString();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        switch (_Act)
        {
            case "Edit": this.doEdit(); break;
            case "Add": this.doAdd(); break;
        }
    }
    private void doEdit()
    {
        if (this.AllowEdit)
        {
            this.editImage();
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }
    private void doAdd()
    {
        if (this.AllowAdd)
        {
            this.insertImage();
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }

    }
    //-----------------------------------------------------------------  
    //private void editImage()
    //{
    //    DataTable dtTmp = bz.getRecord(_ID, "-1");
    //    if (dtTmp.Rows.Count > 0)
    //    {
    //        string sPath = Server.MapPath("~") + "/Images/About/";
    //        //string sSuffix = "About_";
    //        //string sUpload = dtTmp.Rows[0]["Upload"].ToString();
    //        //string strUpload = "";
         
    //        if (bz.updateRecord(_ID, this.txtTitleVN.Text, this.txtTitleEN.Text, Server.HtmlEncode(this.txtContentVN.Text), Server.HtmlEncode(this.txtContentEN.Text), this.rdEnabled_0.Checked ? "0" : "1") > 0)
    //        {
    //            Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
    //            Response.Redirect(Session["Page"].ToString());
    //        }
    //    }
    //}
    private void editImage()
    {

        DataTable dtTmp = bz.getRecord(_ID, "-1");
        if (dtTmp.Rows.Count > 0)
        {
           
            if (bz.updateRecord(_ID, this.txtTitleVN.Text, "", Server.HtmlEncode(this.txtContentVN.Text), Server.HtmlEncode(""), this.rdEnabled_0.Checked ? "0" : "1") > 0)
            {
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
                Response.Redirect(Session["Page"].ToString());
            }

        }
    }
    private void insertImage()
    {

    
     
                
                if (bz.insertRecord(this.txtTitleVN.Text, "", Server.HtmlEncode(this.txtContentVN.Text), Server.HtmlEncode(""), this.rdEnabled_0.Checked ? "0" : "1") > 0)
                {
                    if (this.rdForward_0.Checked)
                        Response.Redirect(Session["Page"].ToString());
                    else this.resetData();
                }
           
    }
    //private void insertImage()
    //{

    //    string sPath = Server.MapPath("~") + "/Images/About/";
    //    //string strLink = "";
    //    //string sSuffix = "About_";
    //    //string sNamePicMain_Thumb = "";
    //    //string sNamePicMain_Full = "";
       
    //    if (bz.insertRecord(this.txtTitleVN.Text, this.txtTitleEN.Text, Server.HtmlEncode(this.txtContentVN.Text), Server.HtmlEncode(this.txtContentEN.Text), this.rdEnabled_0.Checked ? "0" : "1") > 0)
    //    {
    //        if (this.rdForward_0.Checked)
    //            Response.Redirect(Session["Page"].ToString());
    //        else this.resetData();
    //    }
    //}
    protected void btnCencel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Session["Page"].ToString());
    }
}
